package com.sskj.lib.util;

import android.app.Activity;
import android.text.TextUtils;

import com.alibaba.android.arouter.launcher.ARouter;
import com.sskj.common.base.App;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.Constans;
import com.sskj.lib.R;
import com.sskj.lib.RConfig;
import com.sskj.lib.bean.UserData;

public class AppCircleCheckUtil {


    /**
     * 检测是否登录，没有登录直接跳转登录界面
     *
     * @param activity
     * @param userData
     * @return
     */
    public static boolean checkLogin(Activity activity, UserData userData) {
        if (userData == null) {
            ARouter.getInstance().build(RConfig.APP_LOGIN).navigation();
            activity.overridePendingTransition(R.anim.lib_anim_in, R.anim.lib_anim_out);
            return false;
        }
        return true;
    }

    /**
     * 验证手机号
     *
     * @param userData
     * @return
     */
    public static boolean checkTel(Activity activity, UserData userData) {
        if (TextUtils.isEmpty(userData.getMobile())) {
            ToastUtil.showShort( App.INSTANCE.getString(R.string.lib_appCircleCheckUtil1));
            return false;
        }
        return true;
    }

    /**
     * 验证实名认证
     *
     * @param userData
     * @return
     */
    public static boolean checkAuth(Activity activity, UserData userData) {
        if (userData.getStatus() == 1) {
            TipUtil.getSureCancelTip(activity,  App.INSTANCE.getString(R.string.lib_tip), App.INSTANCE. getString(R.string.lib_appCircleCheckUtil3),  App.INSTANCE.getString(R.string.lib_appCircleCheckUtil4), () -> {
                ARouter.getInstance().build(RConfig.MINE_VERIFY_HOME).navigation();
            });
            return false;
        }
        return true;
    }

    /**
     * 验证高级实名认证
     *
     * @param userData
     * @return
     */
    public static boolean checkHighAuth(Activity activity, UserData userData) {
        if (userData.getAuth_status() != 3) {
            TipUtil.getSureCancelTip(activity,  App.INSTANCE.getString(R.string.lib_tip), App.INSTANCE. getString(R.string.lib_appCircleCheckUtil5),  App.INSTANCE.getString(R.string.lib_appCircleCheckUtil4), () -> {
                ARouter.getInstance().build(RConfig.MINE_VERIFY_HOME).navigation();
            });
            return false;
        }
        return true;
    }


    /**
     * 验证交易密码
     *
     * @param userData
     * @return
     */
    public static boolean checkTradePwd(Activity activity, UserData userData) {
//        if (!checkTel(activity, userData)) {
//            return false;
//        }
        if (userData.getIs_pwd() == 1) {
            return true;
        } else {
            TipUtil.getSureCancelTip(activity,  App.INSTANCE.getString(R.string.lib_trade_pwd), App.INSTANCE. getString(R.string.lib_appCircleCheckUtil6),  App.INSTANCE.getString(R.string.lib_appCircleCheckUtil7), () -> {
//                ARouter.getInstance().build(RConfig.MINE_SET_PAY_PWD).withInt("type", 2).withString(Constans.MOBILE, userData.getMobile()).navigation();
                ARouter.getInstance().build(RConfig.MINE_SECURITY_CENTER).navigation();

            });
            return false;
        }
    }

    /**
     * 验证支付方式
     *
     * @param userData
     * @return
     */
    public static boolean checkPayTypeWithTradePwd(Activity activity, UserData userData) {

        if (TextUtils.isEmpty(userData.getPayment_type())) {
            TipUtil.getSureCancelTip(activity,  App.INSTANCE.getString(R.string.lib_tip),  App.INSTANCE.getString(R.string.lib_appCircleCheckUtil8),  App.INSTANCE.getString(R.string.lib_appCircleCheckUtil7), () -> {
                ARouter.getInstance().build(RConfig.MINE_PAYMENT).navigation();
            });
            return false;
        }
        return true;
    }

    /**
     * 验证支付方式
     *
     * @param userData
     * @return
     */
    public static boolean checkPayType(Activity activity, UserData userData) {

        if (TextUtils.isEmpty(userData.getPayment_type())) {
            TipUtil.getSureCancelTip(activity,  App.INSTANCE.getString(R.string.lib_tip), App.INSTANCE. getString(R.string.lib_appCircleCheckUtil9),  App.INSTANCE.getString(R.string.lib_appCircleCheckUtil7), () -> {
                ARouter.getInstance().build(RConfig.MINE_PAYMENT).navigation();
            });
            return false;
        }
        return true;
    }


    /**
     * 验证商家
     *
     * @param userData
     * @return
     */
    public static boolean checkShop(Activity activity, UserData userData) {
//        if (userData.getIs_shop().equals("0")) {  // 不是商家
//            BottomSheetUtil.showShopCheck(activity, () -> {
//                ARouter.getInstance().build(RConfig.MINE_APPLY_SHOP).navigation();
//            }).show();
//            return false;
//        }
        return true;
    }
}
